package com.yochi.pictureseditor.effects.converters;

import java.util.Locale;

public class HueConverter implements ParameterConverter {

	private static final long serialVersionUID = 5255547500500936120L;

	public double convert(double parameter) {
		if(parameter >= 0 && parameter <= 128) {						// returns 0 <= x <= 1
			return (1.0f/128.0f)*parameter;
		} /* else if(parameter >= 128 && parameter <= 256) { */			// returns 1 < x <= 4
			return (3.0f/128.0f)*parameter-2;
	}
	
	public double convertInverse(double value) {
		return (128.0f/100.0f)*value + 128;
	}

	public String toDisplay(double parameter) {
		if(parameter >= 0 && parameter <= 128) {
			return String.format(Locale.FRANCE, "%.1f", convert(parameter)*100-100);
		} /* else if(parameter >= 128 && parameter <= 256) { */
			return String.format(Locale.FRANCE, "%.1f", (100.0f/3.0f)*convert(parameter)-(100.0f/3.0f));
	}

}
